const app = getApp()
const $api = require('../../utils/api.js').API;

Page({
    data: {
        list:{},
        page:1,
        imgUrl:app.globalData.imgUrl,
        pageShow:true,
        banner:''

    },
    onLoad: function() {
        this.getlist();
        this.getBanner();
    },
    getlist:function(){
        var data = {
            'page':this.data.page,
        }
        var that = this
        var list = this.data.list
        $api.get('factory/list',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                if(res.data.data.last_page <= that.data.page){
                    that.setData({
                        pageShow:false
                    })
                }
                if(that.data.page == 1){
                    that.setData({
                        list:res.data.data.data
                    })
                }else{
                    that.setData({
                        list:list.concat(res.data.data.data)
                    })
                }
            }
        }).catch(err => {
            //请求失败
            //console.log('job','请求失败');
        })
    },
    getBanner:function(){
        var that = this;
        var data = {'type':5}
        $api.get('banner',data).then(res => {
            //请求成功
            if(res.data.code == 1){
              that.setData({
                banner:res.data.data[0].img
              })
            }
        })
    },
    onReachBottom: function(t){
        if(this.data.pageShow){
            //当前不是最后一页可加载
            this.setData({
                page: this.data.page + 1,
            })
            this.getlist();
        }
    },
    onShareAppMessage: function() {
        return {
            title: "厂商-天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
    }
});